package com.service;

import com.dao.JobCollectRepository;
import com.model.JobCollect;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Service
@Transactional
public class JobCollectService {

    @Resource
    private JobCollectRepository repository;


    public boolean collect(Long userId, Long jobId) {
        if(!repository.existsByUserIdAndJobInfoId(userId, jobId)) {
            JobCollect jobCollect = new JobCollect().setJobInfoId(jobId).setUserId(userId).setCollectDataTime(LocalDateTime.now());
            repository.save(jobCollect);
            return true;
        }
        return false;
    }
}
